/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Contain the ISO langauges which may be/are associated with an assignment.
 *
 * @author Keith Shie
 */
@Entity
@Table(name = "iso_lang")
@NamedQueries({@NamedQuery(name = "IsoLanguage.findAll", query = "SELECT i FROM IsoLanguage i"),
        @NamedQuery(name = "IsoLanguage.findByLangCd", query = "SELECT i FROM IsoLanguage i WHERE i.languageCode = :languageCode"),
        @NamedQuery(name = "IsoLanguage.findByLangDesc", query = "SELECT i FROM IsoLanguage i WHERE i.languageDescription = :languageDescription")})
public class IsoLanguage implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @Column(name = "lang_cd", nullable = false, length = 8)
  private String languageCode;
  @Column(name = "lang_desc", length = 30)
  private String languageDescription;
  @ManyToMany(mappedBy = "isoLangCollection",fetch=FetchType.LAZY)
  private Collection<AssignmentProperty> asgnPropCollection;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "primaryLanguageCode",fetch=FetchType.LAZY)
  private Collection<AssignmentProperty> asgnPropCollection1;

  public IsoLanguage() {
  }

  public IsoLanguage(String langCd) {
    this.languageCode = langCd;
  }

  public IsoLanguage(String langCd, String langDesc) {
    this.languageCode = langCd;
    this.languageDescription = langDesc;
  }

  public String getLanguageCode() {
    return languageCode;
  }

  public void setLanguageCode(String langCd) {
    this.languageCode = langCd;
  }

  public String getLanguageDescription() {
    return languageDescription;
  }

  public void setLanguageDescription(String langDesc) {
    this.languageDescription = langDesc;
  }

  public Collection<AssignmentProperty> getAsgnPropCollection() {
    return asgnPropCollection;
  }

  public void setAsgnPropCollection(Collection<AssignmentProperty> asgnPropCollection) {
    this.asgnPropCollection = asgnPropCollection;
  }

  public Collection<AssignmentProperty> getAsgnPropCollection1() {
    return asgnPropCollection1;
  }

  public void setAsgnPropCollection1(Collection<AssignmentProperty> asgnPropCollection1) {
    this.asgnPropCollection1 = asgnPropCollection1;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (languageCode != null ? languageCode.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof IsoLanguage)) {
      return false;
    }
    IsoLanguage other = (IsoLanguage) object;
    if ((this.languageCode == null && other.languageCode != null) || (this.languageCode != null && !this.languageCode.equals(other.languageCode))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.IsoLang[langCd=" + languageCode + "]";
  }

}
